<template>
  <div>
    App
    <button @click="handleGet">GET</button>
    <button @click="addPost">POST</button>
    <button @click="updatePost">PUT</button>
    <button @click="patchPost">PATCH</button>
    <button @click="delPost">DELETE</button>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "App",
  methods: {
    async handleGet(){
      try{ const result=await axios.get("/api/admin/product/baseTrademark/1/200")
      console.log(result.data);
      }catch(e){
        console.log(e);
      }
    },
    /* ------------------------------ */
   /*  async getPosts() {
      try {
        const result = await axios({
          method: "GET", // 请求方式
          url: "http://localhost:3000/posts", // 请求地址
          params: {
            // 查询字符串参数
            _limit: 10,
          },
        });

        console.log(result.data);
      } catch (e) {
        console.log(e);
      }
    }, */
    async addPost() {
      try {
        const result = await axios({
          method: "POST",
          url: "http://localhost:3000/posts",
          data: {
            // 请求体参数
            title: "xxx标题",
            content: "xxxxxx内容",
          },
        });
        console.log(result.data);
      } catch (e) {
        console.log(e);
      }
    },
    async updatePost() {
      try {
        const result = await axios({
          method: "PUT",
          url: "http://localhost:3000/posts/a4e3",
          data: {
            title: "zzz标题",
          },
        });
        console.log(result.data);
      } catch (e) {
        console.log(e);
      }
    },
    //改
    async patchPost() {
      try {
        const result = await axios({
          method: "PATCH",
          url: "http://localhost:3000/posts/1",
          data: {
            title: "zzz标题",
          },
        });
        console.log(result.data);
      } catch (e) {
        console.log(e);
      }
    },
    //删
    async delPost() {
      try {
        const result = await axios.delete("http://localhost:3000/posts/1");
        console.log(result.data);
      } catch (e) {
        console.log(e);
      }
    },
  },
};
</script>

<style></style>
